#define  _CRT_SECURE_NO_WARNINGS
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
#include<stdio.h>
typedef struct ListNode ListNode;
struct ListNode
{
    int val;
    struct ListNode* next;
};
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2)
{
    ListNode* newnode = (ListNode*)malloc(sizeof(ListNode));
    ListNode* newhead = newnode;
    ListNode* newtail = newnode;
    ListNode* l1 = list1;
    ListNode* l2 = list2;
    while (l2 && l1)
    {
        if (l1->val >= l2->val)
        {
            newtail->next = l2;
            newtail = newtail->next;
            l2 = l2->next;
        }
        else
        {
            newtail->next = l1;
            newtail = newtail->next;
            l1 = l1->next;
        }
    }
    ListNode* big = l1;
    ListNode* small = l2;
    if (l1 == NULL)
    {
        big = l2;
        small = l1;
    }
    newtail->next = big;
    ListNode* rethead = newhead->next;
    free(newhead);
    return rethead;
}